package com.example.software.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.software.entity.MedicineEntity;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.software.utils.PageUtils;
import com.example.software.utils.Query;

import com.example.software.dao.ApplyDao;
import com.example.software.entity.ApplyEntity;
import com.example.software.service.ApplyService;


@Service("applyService")
public class ApplyServiceImpl extends ServiceImpl<ApplyDao, ApplyEntity> implements ApplyService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {


        LambdaQueryWrapper<ApplyEntity> wrapper = new LambdaQueryWrapper<>();

        if (params.containsKey("doctorId")) {

            Long doctorId = (Long) params.get("doctorId");
            System.out.println("doctorId"+doctorId);
            wrapper.eq(doctorId != null, ApplyEntity::getDoctorId, doctorId);

        }

        if (params.containsKey("state")) {

            Integer state = (Integer) params.get("state");
            System.out.println("state"+state);
            wrapper.eq(state != null, ApplyEntity::getState, state);
        }

        wrapper.orderByDesc(ApplyEntity::getApplyTime);

        IPage<ApplyEntity> page = this.page(
                new Query<ApplyEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

}